<?php
  
function instructInteger($target, $attr, $op, $value, $lastingRound=0, $visible=true)
{
    $v=$visible?'true':'false';
    return <<<EOT
            new FightPetActionEffect('$target','$attr','$op',(int)($value),$lastingRound,$v),\n
EOT;
}

function instructString($target, $attr, $op, $value, $lastingRound=0, $visible=true)
{
    $v=$visible?'true':'false';
    return <<<EOT
            new FightPetActionEffect('$target','$attr','$op','$value',$lastingRound,$v),\n
EOT;
}

function instruct($target, $attr, $op, $value, $lastingRound=0, $visible=true)
{
    return instructInteger($target, $attr, $op, $value, $lastingRound, $visible);
}

function toSleep($target, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'sleep', $lastingRound);
    $result.= instructInteger($target, 'physicalAttackRate', 'set', 0, $lastingRound, false);
    $result.= instructInteger($target, 'skillAttackRate', 'set', 0, $lastingRound, false);
    $result.= instructInteger($target, 'skillHelpRate', 'set', 0, $lastingRound, false);
    $result.= instructInteger($target, 'defendRate', 'set', 0, $lastingRound, false);
    return $result;
}

function toFrightened($target, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'fightened', $lastingRound);
    $result.= instructInteger($target, 'defendRate', 'change', 25, $lastingRound, false);
    return $result;
}

function toTorpid($target, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'torpid', $lastingRound);
    $result.= instructInteger($target, 'physicalAttackRate', 'set', 0, $lastingRound, false);
    $result.= instructInteger($target, 'skillAttackRate', 'set', 0, $lastingRound, false);
    $result.= instructInteger($target, 'skillHelpRate', 'set', 0, $lastingRound, false);
    return $result;
}

function toStiff($target, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'stiff', $lastingRound);
    $result.= instructInteger($target, 'skillAttackRate', 'set', 0, $lastingRound, false);
    $result.= instructInteger($target, 'skillHelpRate', 'set', 0, $lastingRound, false);
    return $result;
}

function toPoisoned($target, $damage, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'poisoned', $lastingRound);
    $result.= instructInteger($target, 'hp', 'change', "-($damage)", $lastingRound);
    return $result;
}

function toDexterityChanged($target, $value, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'dexterityChanged', $lastingRound);
    $result.= instructInteger($target, 'dexterity', 'change', "$value", $lastingRound, false);
    return $result;
}

function toStrengthChanged($target, $value, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'strengthChanged', $lastingRound);
    $result.= instructInteger($target, 'strength', 'change', "$value", $lastingRound, false);
    return $result;
}

function toSpiritChanged($target, $value, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'spiritChanged', $lastingRound);
    $result.= instructInteger($target, 'spirit', 'change', "$value", $lastingRound, false);
    return $result;
}

function toEnduranceChanged($target, $value, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'enduranceChanged', $lastingRound);
    $result.= instructInteger($target, 'endurance', 'change', "$value", $lastingRound, false);
    return $result;
}

function toLightShield($target, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'lightShield', $lastingRound);
    return $result;
}

function toMirrorShield($target, $lastingRound=0)
{
    $result = instructString($target, 'state', 'set', 'mirrorShield', $lastingRound);
    return $result;
}

function swapHp($lastingRound=0)
{
    $result = instructInteger('self', 'hp', 'set', '$enemy->hp');
    $result.= instructInteger('enemy', 'hp', 'set', '$self->hp');
    return $result;
}
  
?>
